from rest_framework.generics import ListAPIView
from .models import CourseCategory
from .serializers import CourseCategoryModelSerializer
from .models import Course
from .serializers import CourseModelSerializer
from rest_framework.filters import OrderingFilter
from .paginations import CoursePageNumberPagination


class CourseCategoryListAPIView(ListAPIView):
    """
    课程分类
    """
    queryset = CourseCategory.objects.filter(is_show=True, is_deleted=False).order_by("orders", "-id")
    serializer_class = CourseCategoryModelSerializer


# from .models import Course
# from .serializers import CourseModelSerializer
# class CourseListAPIView(ListAPIView):
#     """课程列表"""
#     queryset = Course.objects.filter(is_show=True, is_deleted=False).order_by("orders","-id")
#     serializer_class = CourseModelSerializer


class CourseListAPIView(ListAPIView):
    """课程列表"""
    queryset = Course.objects.filter(is_show=True, is_deleted=False).order_by("orders", "-id")
    serializer_class = CourseModelSerializer
    filter_backends = [OrderingFilter]
    ordering_fields = ('id', 'students', 'price')
    pagination_class = CoursePageNumberPagination
